package com.training.nio;

import java.io.FileNotFoundException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIODemo {

	public static void main(String[] args) throws Exception {
		String fileName = "E:\\JavaWork\\java-io\\src\\com\\training\\io\\writer\\WriterDemo.java";
		RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
		
		FileChannel inChannel = raf.getChannel();//读通道
		ByteBuffer buffer = ByteBuffer.allocate(64);
		
		while(inChannel.read(buffer)!=-1) {
			buffer.flip();
			while(buffer.hasRemaining()) {
				System.out.print((char)buffer.get());
			}
			buffer.clear();
		}
		raf.close();

	}

}
